package com.jiawa.train.member.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiawa.train.member.domain.Passenger;
import com.jiawa.train.common.resp.CommonResp;
import com.jiawa.train.member.service.serviceImpl.PassengerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/passenger")
public class PassengerController {

    @Autowired
    private PassengerService passengerService;

    @GetMapping("/list")
    public CommonResp<Page<Passenger>> list(@RequestParam(defaultValue = "1") int pageNum,
                                            @RequestParam(defaultValue = "10") int pageSize) {
        Page<Passenger> page = passengerService.page(new Page<>(pageNum, pageSize));
        return new CommonResp<>(page);
    }

    @GetMapping("/{id}")
    public CommonResp<Passenger> get(@PathVariable Long id) {
        Passenger passenger = passengerService.getById(id);
        return new CommonResp<>(passenger);
    }

    @PostMapping("/save")
    public CommonResp<Boolean> save(@RequestBody Passenger passenger) {
        boolean result = passengerService.saveOrUpdate(passenger);
        return new CommonResp<>(result);
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp<Boolean> delete(@PathVariable Long id) {
        boolean result = passengerService.removeById(id);
        return new CommonResp<>(result);
    }
}
